<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Sms {

	public $config;
	protected $_ci;

	function __construct($url = '') {
		$this -> _ci = &get_instance();
		$this -> _ci -> load -> library('curl');
		$this -> config = $this -> _ci -> config -> item('sms');
	}

	public function status() {
        $respone = $this -> _ci->curl->create($this -> config['endpoint'] . "/smsapibalance.php?userkey={$this->config['user']}&passkey={$this->config['passkey']}");
		$this -> _ci->curl->option(CURLOPT_SSL_VERIFYPEER, 0);
		$response = $this -> _ci->curl->execute();
		$info = $this -> _ci->curl->info;
		if ($info['http_code'] != 200) {
			return FALSE;
		}
		echo "<pre>"; print_r($info);	
			
		return json_decode(json_encode(simplexml_load_string($response)));
	}

	public function send($msisdn, $message) {
                $respone = $this -> _ci->curl->create($this -> config['endpoint'] . "/smsapi.php?userkey={$this->config['user']}&passkey={$this->config['passkey']}&nohp={$msisdn}&pesan={$message}");
                $this -> _ci->curl->option(CURLOPT_SSL_VERIFYPEER, 0);
                $response = $this -> _ci->curl->execute();
                $info = $this -> _ci->curl->info;
                // echo "<pre>"; print_r($info);	
                		
                if ($info['http_code'] != 200) {
                		echo "<pre>"; print_r($info);	
                		return FALSE;
                }
                return json_decode(json_encode(simplexml_load_string($response))); 
	}

}
